package com.eslserver.core;

import java.util.Locale;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.eslserver.core.config.Config;
import com.eslserver.core.config.ESLServerConfig;

@SuppressWarnings("serial")
public class ESLServerCore extends HttpServlet {
	public static final Logger LOG = LoggerFactory
			.getLogger(ESLServerCore.class);

	public static final String DEFAULT_CONF_FILE = "WEB-INF/eslserverconfig.xml";

	private static ESLServerConfig eslServerConfig;

	@Override
	public void init(ServletConfig config) throws ServletException {
		// set locale to EN
		Locale.setDefault(Locale.ENGLISH);

		// initialize ESLServer config
		eslServerConfig = ESLServerConfig.getInstance(config
				.getServletContext().getResourceAsStream(DEFAULT_CONF_FILE));

		ESLServerDBInitializer.initDB();
		ESLAttachmentInitializer.initAttachment();
		STiTEQHTTPServerInitializer.initHTTPServer();
		ScheduleTimerInitializer.initScheduleTimer();

		LOG.info("ESLServer Core Loaded Successfully!");
	}

	public static Config getESLServerConfig() {
		return eslServerConfig;
	}
}
